package com.broada.apm.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.broada.apm.ajax.PerformanceResult;
import com.broada.apm.ajax.Result;
import com.broada.apm.ajax.TransactionResult;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("apm/trades")
@Api(value="apm/trades" , description = "交易类型，交易渠道相关的APIs")
@Produces(MediaType.APPLICATION_JSON)
public interface TransactionService {
	/**
	 * 业务交易所有请求
	 * 
	 * @param appId
	 * @param nodeId
	 * @param vsite
	 * @param orderBy
	 * @param desc
	 * @param keyWord
	 * @param tradeIp
	 * @param tradeProto
	 * @param startDate
	 * @param endDate
	 * @param top
	 * @param pageSize
	 * @param pageIndex
	 * @return
	 */
	@GET
	@Path("/performances/total")
	@ApiOperation(value = "业务交易所有请求")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult getTradesPerformancesTotal(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId,
			@ApiParam(value = "节点id", required = true) @QueryParam("nodeId") String nodeId, 
			@ApiParam(value = "domain id", required = true) @QueryParam("vsite") String vsite,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy, 
			@ApiParam(value = "排序顺序，true为降序", required = false) @QueryParam("desc") boolean desc,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord, 
			@ApiParam(value = "目的节点ip", required = false) @QueryParam("tradeIp") String tradeIp,
			@ApiParam(value = "目的节点协议号", required = false) @QueryParam("tradeProto") String tradeProto, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "返回记录数", required = true) @QueryParam("top") int top, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex);

	/**
	 * 交易跟踪
	 * 
	 * @param keyWord
	 * @param transactionType
	 * @param transactionChannel
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@GET
	@Path("/tracking")
	@ApiOperation(value = "交易跟踪")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult tradeTracking(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "交易标记", required = true) @QueryParam("transactionFlag") String transactionFlag, 
			@ApiParam(value = "节点id", required = true) @QueryParam("agentId") String serviceId,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord, 
			@ApiParam(value = "交易类型", required = false) @QueryParam("transactionType") String transactionType,
			@ApiParam(value = "交易渠道", required = false) @QueryParam("transactionChannel") String transactionChannel, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex,
			@ApiParam(value = "是否显示交易拓扑图", required = true) @QueryParam("tracking") String tracking);
	
	
	/**
	 * 同一交易类型或交易渠道查询
	 * 
	 * @param serviceId
	 * @param keyWord
	 * @param transactionType
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@GET
	@Path("/type")
	@ApiOperation(value = "交易类型或交易渠道查询")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult tradeAllType(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "查询类型", required = true) @QueryParam("type") String type,
			@ApiParam(value = "节点id", required = true) @QueryParam("agentId") String agentId,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord, 
			@ApiParam(value = "交易类型", required = false) @QueryParam("transactionType") String transactionType,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex);


	/**
	 * 交易类型列表导出
	 * 
	 * @param request
	 * @param response
	 * @param serviceId
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("/downloadTransaction")
	@ApiOperation(value = "交易类型列表下载")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult downloadTransactionType(@Context HttpServletRequest request, @Context HttpServletResponse response,
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "节点id", required = true) @QueryParam("serviceId") String serviceId,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord, 
			@ApiParam(value = "交易类型", required = false) @QueryParam("transactionType") String transactionType, 
			@QueryParam("name") String name, 
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate) throws Exception;
	
	/**
	 * 交易渠道列表导出
	 * @param request
	 * @param response
	 * @param appId
	 * @param serviceId
	 * @param keyWord
	 * @param transaction
	 * @param name
	 * @param orderBy
	 * @param desc
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("/downloadTransactionChannel")
	@ApiOperation(value = "交易渠道列表下载")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult downloadTransactionChannel(@Context HttpServletRequest request, @Context HttpServletResponse response,
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "节点id", required = true) @QueryParam("serviceId") String serviceId,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "交易渠道", required = false) @QueryParam("transactionChannel") String transactionChannel,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate) throws Exception;
	
	/**
	 * 多维统计
	 * @param dismension  
	 * @param typeName
	 * @param channelName
	 * @param destIp
	 * @param srcIp
	 * @param responseCode
	 * @param appId
	 * @param serviceId
	 * @param keyWord
	 * @param startDate
	 * @param endDate
	 * @param orderBy
	 * @param desc
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("/multiStatistic")
	@ApiOperation(value = "多维统计")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult multiStatistic(
			@ApiParam(value = "agentId", required = false) @QueryParam("agentId") String agentId, 
			@ApiParam(value = "交易类型", required = true) @QueryParam("typeName") String transactionType, 
			@ApiParam(value = "交易渠道", required = true) @QueryParam("channelName") String transactionChannel,
			@ApiParam(value = "目的ip", required = false) @QueryParam("dstIp") String dstIp,
			@ApiParam(value = "来源ip", required = false) @QueryParam("srcIp") String srcIp,
			@ApiParam(value = "返回码", required = false) @QueryParam("responseCode") String responseCode,
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc,
			@ApiParam(value = "分组字段", required = true)@QueryParam("groupBy") String groupBy,
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex) throws Exception;
	
	@GET
	@Path("/downloadMultiStatistic")
	@ApiOperation(value = "多维统计csv下载")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult downloadMultiStatistic(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@Context HttpServletRequest request, @Context HttpServletResponse response,
			@ApiParam(value = "交易类型", required = true) @QueryParam("typeName") String transactionType, 
			@ApiParam(value = "交易渠道", required = true) @QueryParam("channelName") String transactionChannel,
			@ApiParam(value = "目的ip", required = false) @QueryParam("dstIp") String dstIp,
			@ApiParam(value = "来源ip", required = false) @QueryParam("srcIp") String srcIp,
			@ApiParam(value = "返回码", required = false) @QueryParam("responseCode") String responseCode,
			@ApiParam(value = "节点id", required = false) @QueryParam("serviceId") String serviceId, 
			@ApiParam(value = "关键词", required = false) @QueryParam("keyWord") String keyWord,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy,
			@ApiParam(value = "排序方向，true为降序", required = false) @QueryParam("desc") boolean desc,
			@ApiParam(value = "分组字段", required = true)@QueryParam("groupBy") String groupBy,
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex) throws Exception;
	
	@GET
	@Path("/transactionDetail/{transactionId}")
	@ApiOperation(value = "交易记录")
	@Produces(MediaType.APPLICATION_JSON)
	public Result transactionDetail(
			@ApiParam(value = "交易id", required = true) @PathParam("spanId") String spanId, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate) throws Exception;
	
	@GET
	@Path("/channel")
	@ApiOperation(value = "查询交易渠道")
	@Produces(MediaType.APPLICATION_JSON)
	public TransactionResult queryTransactionChannel(@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId);
	
	@GET
	@Path("/type")
	@ApiOperation(value = "查询交易类型")
	@Produces(MediaType.APPLICATION_JSON)
	public TransactionResult queryTransactionType(@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId);
	
}
